﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dao;
using Utils;
using System.Data;

namespace Website.uc
{
    public partial class ucAdminLogin : System.Web.UI.UserControl
    {
        UserDao userDao = new UserDao();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if(CheckValidate.CheckNull(txtUser.Text)){
                Utility.ShowMessage("Enter Username !!" , Page);
                txtUser.Focus();
            }
            else if (CheckValidate.CheckNull(txtPass.Text))
            {
                Utility.ShowMessage("Enter Password !!", Page);
                txtPass.Focus();
            }
            else
            {
                DataTable tb = userDao.adminLogin(txtUser.Text , txtPass.Text);
                if (tb.Rows.Count > 0)
                {
                    Session["admin"] = txtUser.Text;
                    Response.Redirect("PageAdminUser.aspx");
                }
                else
                {
                    Utility.ShowMessage("Login fail !!" , Page);
                }
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            txtUser.Text = "";
            txtPass.Text = "";
        }
    }
}